home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
Source
/
DBL Pascal Library
/
Utils
/
NuPopUpUtils
< prev
Wrap
Text File
|
1993-03-30
|
5KB
|
181 lines
unit NuPopUpUtils;
interface
{Create a new, empty menu for the specified pop up. Get rid of it only with DisposeDPopUpMenu.}
function NewDPopUpMenu (item: Integer; title: Str255): MenuHandle;
{Dispose of the menu for the specified pop up. Any submenus are also disposed. Create submenus with NewMenu!}
procedure DisposeDPopUpMenu (item: Integer);
{Load a MENU resource for the specified pop up. Any submenus are also loaded. Rid only with ReleaseDPopUpMenu.}
procedure GetDPopUpMenu (item: Integer);
{Release the menu for the specified pop up. Any submenus are also released. Create submenus with GetMenu!}
procedure ReleaseDPopUpMenu (item: Integer);
{Return the menu handle for the specified pop up. Works for both kinds…}
function GetDPopUpMHandle (item: Integer): MenuHandle;
{Return the menu ID for the specified pop up. Works for both kinds…}
function GetDPopUpMenuID (item: Integer): Integer;
{Return the item count, or 0 for a nil menu handle.}
function GetDPopupItemCount (item: Integer): Integer;
{Track an invisible pop up at the specified point.}
procedure TrackInvisibleDPopUp (item: Integer; localPt: Point);
{Force an editable pop up to capture its associated TE field’s contents.}
{You need to do this before the pop up may have to be redrawn, like when you cover it with}
{another window. Note that you specify the dialog item ID of the pop up, not it’s TE field.}
procedure CapturePopUpTE (whichPopUp: Integer);
implementation
uses
NuDialogUtils;
function GetDPopUpMenuID (item: Integer): Integer;
type
popupPrivateData = record
mHandle: MenuHandle;
mID: Integer;
end;
popupPrivateDataPtr = ^popupPrivateData;
popupPrivateDataHdl = ^popupPrivateDataPtr;
begin
GetDPopUpMenuID := popupPrivateDataHdl(GetDControlHandle(item)^^.contrlData)^^.mID;
end;
function NewDPopUpMenu (item: Integer; title: Str255): MenuHandle;
var
menuID: Integer;
menuH: MenuHandle;
begin
menuID := GetDPopUpMenuID(item);
menuH := NewMenu(menuID, title);
if menuH <> nil then
InsertMenu(menuH, -1);
NewDPopUpMenu := menuH;
end;
type
RemoveKind = (Dispose, Release);
procedure RecursiveRemoveMenu (menuH: MenuHandle; kind: RemoveKind);
var
i: Integer;
cmd, mark: Char;
begin
if menuH <> nil then
begin
for i := 1 to CountMItems(menuH) do
begin
GetItemMark(menuH, i, mark);
GetItemCmd(menuH, i, cmd);
if cmd = CHR($1B) then
RecursiveRemoveMenu(GetMHandle(ORD(mark)), kind);
end;
DeleteMenu(menuH^^.menuID);
case kind of
Dispose:
DisposeMenu(menuH);
Release:
ReleaseResource(Handle(menuH));
{no otherwise…}
end;
end;
end;
procedure DisposeDPopUpMenu (item: Integer);
var
menuID: Integer;
menuH: MenuHandle;
begin
menuID := GetDPopUpMenuID(item);
menuH := GetMHandle(menuID);
RecursiveRemoveMenu(menuH, Dispose);
end;
procedure RecursiveGetMenu (menuH: MenuHandle);
var
i: Integer;
cmd, mark: Char;
begin
if menuH <> nil then
begin
InsertMenu(menuH, -1);
for i := 1 to CountMItems(menuH) do
begin
GetItemMark(menuH, i, mark);
GetItemCmd(menuH, i, cmd);
if cmd = CHR($1B) then
RecursiveGetMenu(GetMenu(ORD(mark)));
end;
end;
end;
procedure GetDPopUpMenu (item: Integer);
var
menuID: Integer;
menuH: MenuHandle;
begin
menuID := GetDPopUpMenuID(item);
menuH := GetMenu(menuID);
RecursiveGetMenu(menuH);
end;
procedure ReleaseDPopUpMenu (item: Integer);
var
menuID: Integer;
menuH: MenuHandle;
begin
menuID := GetDPopUpMenuID(item);
menuH := MenuHandle(GetResource('MENU', menuID));
RecursiveRemoveMenu(menuH, Release);
end;
function GetDPopUpMHandle (item: Integer): MenuHandle;
var
menuID: Integer;
begin
menuID := GetDPopUpMenuID(item);
GetDPopUpMHandle := GetMHandle(menuID);
end;
function GetDPopupItemCount (item: Integer): Integer;
var
myMH: MenuHandle;
begin
myMH := GetDPopUpMHandle(item);
if myMH = nil then
GetDPopupItemCount := 0 {This isn’t the value the ROM would give you!}
else
GetDPopupItemCount := CountMItems(myMH);
end;
procedure TrackInvisibleDPopUp (item: Integer; localPt: Point);
var
controlH: ControlHandle;
value: Integer;
begin
controlH := GetDControlHandle(item);
MoveControl(controlH, localPt.h, localPt.v);
value := TrackControl(controlH, localPt, POINTER(-1));
end;
procedure CapturePopUpTE (whichPopUp: Integer);
var
theDialog: DialogPtr;
itemKind: Integer;
itemHandle: Handle;
itemRect: Rect;
saveHilite: Byte;
begin
GetPort(GrafPtr(theDialog));
GetDItem(theDialog, whichPopUp, itemKind, itemHandle, itemRect);
saveHilite := ControlHandle(itemHandle)^^.contrlHilite;
HiliteControl(ControlHandle(itemHandle), 1);
HiliteControl(ControlHandle(itemHandle), saveHilite);
end;
end.